package com.yn.springboot.demo_locale.utils;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * @ClassName: MessageSourceUtil
 * @Description:
 * @author: 王胜
 * @date 2021/4/1
 * @Version: 1.0
 **/
@Component
public class MessageSourceUtil {
    private static MessageSource messageSource;
    public MessageSourceUtil(MessageSource messageSource){
        this.messageSource=messageSource;
    }
    public static String getMessage(String title){
        return messageSource.getMessage(title,null, LocaleContextHolder.getLocale());
    }
    public static String getMessage(String title, Locale locale){
        return messageSource.getMessage(title,null, locale);
    }
    public static String getMessage(String title,Object[] value,Locale locale){
        return messageSource.getMessage(title,value, locale);
    }
}
